package smedi.ismedi.mobile.bff.controller.securityman;

import com.smedi.ismedi.securityman.api.dto.request.AddTrainingRecordRequest;
import com.smedi.ismedi.securityman.api.dto.request.OfficerManagementPageRequest;
import com.smedi.ismedi.securityman.api.dto.response.AddOfficerListResultResponse;
import com.smedi.ismedi.securityman.api.dto.response.TrainingRecordResponse;
import com.smedi.ismedi.securityman.api.feign.RemoteTrainingRecordFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 培训记录
 *
 * @author xuyuanqiao
 * @date 2021/09/23
 */
@Slf4j
@Api(value = "培训记录接口", tags = {"培训记录接口"})
@RequestMapping(value = "/mobilebff/v1/TrainingRecord")
@RestController
@AllArgsConstructor
public class TrainingRecordController {
    private final RemoteTrainingRecordFeignApi remoteTrainingRecordFeignApi;

    /**
     * 通过文件导入添加培训记录
     *
     * @param addTrainingRecordRequest   培训记录信息
     * @return ResponseData<List<String>>
     */
    @ApiOperation(value = "通过文件导入添加培训记录", nickname = "通过文件导入添加培训记录", httpMethod = "POST", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", name = "file", value = "excel", dataType = "file")
    })
    @PostMapping(value = "/addList", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseData<List<AddOfficerListResultResponse>> postImportAddTrainingRecord(AddTrainingRecordRequest addTrainingRecordRequest){
        return remoteTrainingRecordFeignApi.postImportAddTrainingRecord(addTrainingRecordRequest);
    }

    /**
     * 分页查询培训记录
     *
     * @param officerManagementPageRequest   培训记录信息
     * @return ResponseData<List<String>>
     */
    @ApiOperation(value = "分页查询培训记录", httpMethod = "POST")
    @PostMapping(value = "/pageList")
    ResponseData<PaginationData<TrainingRecordResponse>> postQueryTrainingRecord(@Validated @RequestBody OfficerManagementPageRequest officerManagementPageRequest){
        return remoteTrainingRecordFeignApi.postQueryTrainingRecord(officerManagementPageRequest);
    }

    /**
     * 查询培训记录详情
     *
     * @param officerManagementId   培训记录id
     * @return ResponseData<TrainingRecordResponse>
     */
    @ApiOperation(value = "查询培训记录详情", httpMethod = "GET")
    @GetMapping(value = "/detail")
    ResponseData<TrainingRecordResponse> getQueryTrainingRecord(@RequestParam(value = "officerManagementId", required = true) Long officerManagementId){
        return remoteTrainingRecordFeignApi.getQueryTrainingRecord(officerManagementId);
    }

    /**
     * 删除培训记录
     *
     * @param trainingRecordIds   培训记录ids
     * @return ResponseData<Long>
     */
    @ApiOperation(value = "删除培训记录", httpMethod = "DELETE")
    @DeleteMapping(value = "/delete")
    ResponseData<Long> deleteTrainingRecords(@Validated @RequestBody List<Long> trainingRecordIds){
        return remoteTrainingRecordFeignApi.deleteTrainingRecords(trainingRecordIds);
    }

    /**
     * 上岗
     *
     * @param officerManagementId  干事id
     * @param trainingRecordId   培训记录id
     * @return ResponseData<Long>
     */
    @ApiOperation(value = "培训后上岗", httpMethod = "GET")
    @GetMapping(value = "/onDuty")
    ResponseData<Boolean> getOnDuty(@RequestParam(value = "officerManagementId", required = true) Long officerManagementId,
                                    @RequestParam(value = "trainingRecordId", required = true)Long trainingRecordId){
        return remoteTrainingRecordFeignApi.getOnDuty(officerManagementId,trainingRecordId);
    }

    /**
     * 下载导入培训记录附件模板
     *
     * @return ResponseEntity<byte [ ]>
     */
    @ApiOperation(httpMethod = "POST", value = "下载导入培训记录附件模板")
    @PostMapping(value = "/downloadTemplate")
    ResponseEntity<byte[]> postDownloadTemplate() throws IOException{
        return remoteTrainingRecordFeignApi.postDownloadTemplate();
    }

}
